home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / 3d_tools / irit40s.lha / Irit / irit.el < prev    next >
Encoding:
Text File  |  1993-12-30  |  7.1 KB  |  196 lines

  1. ; irit.el - Definitions of IRIT mode for emacs editor.
  2. ; Author:    Gershon Elber
  3. ;         Computer Science Dept.
  4. ;         University of Utah
  5. ; Date:    Tue May 14 1991
  6. ; Copyright (c) 1991, Gershon Elber
  7. ;
  8. ; This file defines an environment to run edit and execute IRIT programs.
  9. ; Such a program should have a '.irt' extension in order it to be in
  10. ; irit-mode major mode. Several new functions are provided to communicate
  11. ; between the editted file and the solid modeller:
  12. ;
  13. ; 1. send-line-to-irit - sends a single line to the solid modeller for
  14. ;    execution. A line is defined from current position to the next
  15. ;    semicolon ';'. If however several commands exists on the same line
  16. ;    they will all be send as one line.
  17. ;    Bounded to Meta-E by default.
  18. ; 2. send-region-to-irit - sends the region from the current mark (mark-marker)
  19. ;    to current position (point-marker) to the solid modeller. This function
  20. ;    is convenient for sending a large block of commands.
  21. ;    Bounded to Meta-R by default.
  22. ; 3. send-mini-buffer-to-irit - sends a line retrieved via the mini buffer to
  23. ;    the solid modeller for execution. The line is appended with a new line
  24. ;    and is echoed to the irit-solid-modeller buffer if irit-echo-program.
  25. ;    Bounded to Meta-S by default.
  26. ;
  27. ; Both functions checks for existance of a buffer named irit-solid-modeller
  28. ; and a process named "irit" hooked to it, and will restart a new process
  29. ; or buffer if none exists. The program to execute as process "irit" is
  30. ; defined by the irit-program constant below.
  31. ;
  32.  
  33. (defvar irit-program "irit"
  34.   "*The executable to run for irit-solid-modeller buffer.")
  35.  
  36. (defvar irit-echo-program nil
  37.   "*Control echo of executed commands to irit-solid-modeller buffer.")
  38.  
  39. (defvar irit-mode-map nil "")
  40. (if irit-mode-map
  41.     ()
  42.   (setq irit-mode-map (make-sparse-keymap))
  43.   (define-key irit-mode-map "\M-s" 'send-mini-buffer-to-irit)
  44.   (define-key irit-mode-map "\M-e" 'send-line-to-irit)
  45.   (define-key irit-mode-map "\M-r" 'send-region-to-irit))
  46.  
  47. ;;;
  48. ;;; Define the irit-mode
  49. ;;;
  50. (defun irit-mode ()
  51.   "Major mode for editing and executing IRIT files.
  52.  
  53. see send-line-to-irit and send-region-to-irit for more."
  54.   (interactive)
  55.   (use-local-map irit-mode-map)
  56.   (setq major-mode 'irit-mode)
  57.   (setq mode-name "Irit")
  58.   (run-hooks 'irit-mode-hook))
  59.  
  60. ;;;
  61. ;;; Define send-min-buffer-to-irit - send one line prompt for at the mini
  62. ;;; buffer, to the irit buffer.
  63. ;;;
  64. (defun send-mini-buffer-to-irit ()
  65.   "Sends one line of code from mini-buffer to the IRIT program.
  66.  
  67. The IRIT solid modeller buffer name is irit-solid-modeller and the 
  68. process name is 'irit'. If none exists, a new one is created.
  69.  
  70. The name of the irit program program to execute is stored in irit-program
  71. and may be changed."
  72.   (interactive)
  73.   (if (equal major-mode 'irit-mode)
  74.     (progn
  75.       (make-irit-buffer)     ; In case we should start a new one.
  76.       (let* ((crnt-buffer (buffer-name))
  77.          (string-copy (read-from-minibuffer "Irit> ")))
  78.     (switch-to-buffer-other-window (get-buffer "irit-solid-modeller"))
  79.     (end-of-buffer)
  80.     (if irit-echo-program
  81.       (insert string-copy))
  82.     (if (not (pos-visible-in-window-p))
  83.       (recenter 3))
  84.     (process-send-string "irit" string-copy)
  85.     (process-send-string "irit" "\n")
  86.     (switch-to-buffer-other-window (get-buffer crnt-buffer))))
  87.     (message "Should be invoked in irit-mode only.")))
  88. ;;;
  89. ;;; Define send-line-to-irit - send from current cursor position to next
  90. ;;; semicolon detected.
  91. ;;;
  92. (defun send-line-to-irit ()
  93.   "Sends one line of code from current buffer to the IRIT program.
  94.  
  95. Use to execute a line in the IRIT solid modeller. A line is anything
  96. that is terminated by a semicolon, but is at least one line of text so
  97. multiple commands per line (with several semicolons) are still
  98. considered a single line.
  99.  
  100. The IRIT solid modeller buffer name is irit-solid-modeller and the 
  101. process name is 'irit'. If none exists, a new one is created.
  102.  
  103. The name of the irit program program to execute is stored in irit-program
  104. and may be changed."
  105.   (interactive)
  106.   (if (equal major-mode 'irit-mode)
  107.     (progn
  108.       (make-irit-buffer)        ; In case we should start a new one.
  109.       (beginning-of-line)
  110.       (let ((start-mark (point-marker)))
  111.     (search-forward ";")
  112.     (let ((end-one-mark (point-marker)))
  113.       (goto-char start-mark)
  114.       (beginning-of-line)
  115.       (next-line 1)
  116.       (let* ((crnt-buffer (buffer-name))
  117.              (end-two-mark (point-marker))
  118.              (end-max-mark (max end-one-mark end-two-mark))
  119.          (string-copy (buffer-substring start-mark end-max-mark)))
  120.         (switch-to-buffer-other-window (get-buffer "irit-solid-modeller"))
  121.         (end-of-buffer)
  122.         (if irit-echo-program
  123.           (insert string-copy))
  124.         (set-marker (process-mark (get-process "irit")) (point-marker))
  125.         (if (not (pos-visible-in-window-p))
  126.           (recenter 3))
  127.         (switch-to-buffer-other-window (get-buffer crnt-buffer))
  128.         (process-send-region "irit" start-mark end-max-mark)
  129.         (goto-char end-max-mark)
  130.         (if (equal "\n" (buffer-substring (point-marker)
  131.                           (+ 1 (point-marker))))
  132.           (process-send-string "irit" "\n"))  
  133.         (if (> end-one-mark end-two-mark)
  134.           (forward-char 1))))))
  135.     (message "Should be invoked in irit-mode only.")))
  136.  
  137. ;;;
  138. ;;; Define send-region-to-irit - send from current cursor position to
  139. ;;; current marker.
  140. ;;;
  141. (defun send-region-to-irit ()
  142.   "Sends a region of code from current buffer to the IRIT program.
  143.  
  144. When this function is invoked on an IRIT file it send the region from current
  145. point to current mark to the irit solid modeller.
  146.  
  147. The IRIT solid modeller buffer name is irit-solid-modeller and the
  148. process name is 'irit'. If none exists, a new one is created.
  149.  
  150. The name of the irit program program to execute is stored in irit-program
  151. and may be changed."
  152.   (interactive)
  153.   (if (equal major-mode 'irit-mode)
  154.     (progn
  155.       (make-irit-buffer)     ; In case we should start a new one.
  156.       (copy-region-as-kill (mark-marker) (point-marker))
  157.       (let ((crnt-buffer (buffer-name)))
  158.     (switch-to-buffer-other-window (get-buffer "irit-solid-modeller"))
  159.     (end-of-buffer)
  160.     (if irit-echo-program
  161.       (yank))
  162.     (set-marker (process-mark (get-process "irit")) (point-marker))
  163.     (if (not (pos-visible-in-window-p))
  164.       (recenter 3))
  165.     (switch-to-buffer-other-window (get-buffer crnt-buffer))
  166.     (process-send-region "irit" (mark-marker) (point-marker))))
  167.     (message "Should be invoked in irit-mode only.")))
  168.  
  169. ;;;
  170. ;;; Switch to "irit-solid-modeller" buffer if exists. If not, creates one and
  171. ;;; execute the program defined by irit-program.
  172. ;;;
  173. (defun make-irit-buffer ()
  174.   "Switch to irit-solid-modeller buffer or create one if none exists"
  175.   (interactive)
  176.   (if (get-buffer "irit-solid-modeller")
  177.     (if (not (get-process "irit"))
  178.       (progn
  179.     (message "Starting IRIT solid modeller...")
  180.     (start-process "irit" "irit-solid-modeller" irit-program)
  181.     (process-send-string "irit" "\n")
  182.     (message "Done.")))
  183.     (progn
  184.       (message "Starting IRIT solid modeller...")
  185.       (start-process "irit" "irit-solid-modeller" irit-program)
  186.       (process-send-string "irit" "\n")
  187.       (message "Done."))))
  188.  
  189. ;;;
  190. ;;; Autoload irit-mode on any file with irt extension. 
  191. ;;;
  192. (setq auto-mode-alist (append '(("\\.irt$" . irit-mode))
  193.                   auto-mode-alist))
  194.